import axios from 'axios'
import NproGress from 'nprogress'
import { message } from 'antd'
import 'nprogress/nprogress.css'
const http = axios.create({
  timeout: 30000,
  baseURL: 'https://bjwz.bwie.com'
})

http.interceptors.request.use((config) => {
  NproGress.start()
  return config
})

http.interceptors.response.use(
  (data) => {
    NproGress.done()
    // eslint-disable-next-line no-extra-boolean-cast
    if (Boolean(data.data.msg)) {
      void message.success(data.data.msg)
    }
    return data.data
  },
  (error) => {
    switch (error.response.data.statusCode) {
      case 401:
        void message.error(error.response.data.msg)
    }
  }
)

export default http
